package com.hualian.invest.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.hualian.invest.service.InvestService;
import com.hualian.util.http.RequestUtil;


@RestController
@RequestMapping("/invest")
public class InvestController {

	@Autowired
	private InvestService investService;
	
	/**
	 * 查询产品信息
	 * @return
	 */
	@RequestMapping("/getProKinds")
	public Map<String,Object> getProKinds(int proId){
		return investService.getProKinds(proId);
	}
	/**
	 * 跳转到产品页面
	 * @return
	 */
	@RequestMapping("/investHome")
	public ModelAndView gotoInvestHome(){
		ModelAndView view =new ModelAndView();
		view.setViewName("/invest/investHome");
		return view;
	}
	/**
	 * 跳转到订单页面
	 * @return
	 */
	@RequestMapping("/investOrder")
	public ModelAndView gotoInvestOrder(){
		ModelAndView view =new ModelAndView();
		view.setViewName("/invest/investOrder");
		return view;
	}
	/**
	 * 跳转到支付页面
	 * @return
	 */
	@RequestMapping("/orderPay")
	public ModelAndView gotoOrderPay(){
		ModelAndView view =new ModelAndView();
		view.setViewName("/invest/orderPay");
		return view;
	}
	/**
	 * 跳转到支付成功页面
	 * @return
	 */
	@RequestMapping("/success")
	public ModelAndView gotoSuccess(){
		ModelAndView view =new ModelAndView();
		view.setViewName("/invest/success");
		return view;
	}
	
	@RequestMapping("/payProduct")
	public Map<String, Object> payProduct(HttpServletRequest request){
		Map<String, Object> jsom = new HashMap<String, Object>();
		Map<String,Object> data = RequestUtil.convertParamToMap(request);
		int num = investService.payProduct(data);
		if (num == 1) {
			jsom.put("success", true);
			return jsom;
		} else {
			jsom.put("success", false);
			return jsom;
		}
	}


	
	
	
}
